package com.bobi.tfca.utils;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * Description: 完整打印异常日志
 */
public class MessageUtils {

    /**
     * 完整打印异常日志信息
     * @param e 异常对象
     * @return 完整的异常信息字符串
     */
    public static String getErrMsg(Exception e) {
        if (e == null) {
            return "异常为null";
        }
        StringWriter sw = null;
        PrintWriter pw = null;

        try {
            sw = new StringWriter();
            pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            pw.flush();
            sw.flush();
        } finally {
            if (sw != null) {
                try {
                    sw.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
            if (pw != null) {
                pw.close();
            }
        }
        return sw.toString();
    }
}
